package com.yxy.controller;

import com.yxy.base.BusinessException;
import com.yxy.base.Pagingable;
import com.yxy.base.RestResponse;
import com.yxy.dto.TableUserAddressDto;
import com.yxy.service.TableUserAddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author huangxinrong
 * 商品订单管理
 */
@RestController
@Slf4j
  @RequestMapping("/tableUserAddress")//必须要加
public class TableUserAddressController {

  @Autowired
  private TableUserAddressService tableUserAddressService;

  // 获取商品订单列表
  @Pagingable//添加分页
  @PostMapping("/list")
  public RestResponse getList(@RequestBody TableUserAddressDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableUserAddressService.getlist(pojo));
    return restResponse;
  }

  // app获取个人地址列表
  @PostMapping("/listCount")
  public RestResponse getListCount(@RequestBody TableUserAddressDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableUserAddressService.getlist(pojo));
    return restResponse;
  }

  // 获取商品订单列表
  @Pagingable//添加分页
  @PostMapping("/appStoreList")
  public RestResponse getAppStoreList(@RequestBody TableUserAddressDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableUserAddressService.getlist(pojo));
    return restResponse;
  }

  //修改用户地址信息
  @PostMapping("/update")
  public RestResponse update(@RequestBody @Valid  TableUserAddressDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableUserAddressService.modify(pojo));
    return restResponse;
  }


  //修改用户地址信息
  @PostMapping("/appUpdate")
  public RestResponse appUpdate(@RequestBody @Valid  TableUserAddressDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableUserAddressService.appUpdate(pojo));
    return restResponse;
  }

  //新增用户地址信息
  @PostMapping("/create")
  public RestResponse create(@RequestBody @Valid  TableUserAddressDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableUserAddressService.save(pojo));
    return restResponse;
  }





  //新增用户地址信息
  @PostMapping("/appCreate")
  public RestResponse appCreate(@RequestBody @Valid  TableUserAddressDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableUserAddressService.appCreate(pojo));
    return restResponse;
  }



  //根据id删除用户地址信息
  @PostMapping("/delete")
  public RestResponse delete(@RequestBody @Valid  TableUserAddressDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableUserAddressService.delete(pojo.getId().toString()));
    return restResponse;
  }
}
